/*
 * Copyright © 2022 XXXXXXXXX
 * @Author: zhangxiang
 * @Date: 2022-07-19 09:42:10
 * @LastEditors: zhangxiang
 * @LastEditTime: 2023-09-21 16:10:42
 * @Description:
 *
 */

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

import cnMgmtRouter from './modules/cn-mgmt' // 算网纳管
import cnResourceRouter from './modules/cn-resource' // 算力资源
import orchestrateRouter from './modules/orchestrate' // 业务编排
import clusterMgmtRouter from './modules/hybrid-cloud' // 集群管理
import schedulingEngineRouter from './modules/scheduling-engine' // 调度引擎
import appServiceRouter from './modules/app-service' // 应用服务
import intelligentSchedulingRouter from './modules/intelligent-scheduling' // 智能调度
import monitorRouter from './modules/monitor' // 系统监控
import systemMgmtRouter from './modules/system-mgmt' // 系统管理

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * alwaysAdd                      always add the route when it's in asyncRoute
 * meta : {
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
    menuKey: 'menu1'             the menu's unique key, async control whether the menu page could enter
    copyright: true              whether show the copyright (default is true)
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect', // 重定向
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login', // 登录
    component: () => import('@/views/login/index'),
    meta: {
      title: '系统登录'
    },
    hidden: true
  },
  {
    path: '/register', // 注册
    component: () => import('@/views/register/index'),
    meta: {
      title: '用户注册'
    },
    hidden: true
  },
  {
    path: '/404', // 404
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/situation', // 态势大屏
    component: () => import('@/views/situation/index'),
    meta: {
      title: '资源概览'
    },
    hidden: true
  },
  {
    path: '/',
    redirect: '/cn-mgmt/index',
    hidden: true
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: location.origin + '/#/situation',
    component: Layout,
    redirect: '/situation',
    children: [
      {
        path: '',
        name: 'Index',
        redirect: '/situation',
        component: () => import('@/views/index/index'),
        meta: { title: '资源概览', icon: 'index', menuKey: 'Overview', menuNameKey: 'Overview' }
      }
    ]
  },
  cnMgmtRouter,
  cnResourceRouter,
  orchestrateRouter,
  clusterMgmtRouter,
  schedulingEngineRouter,
  appServiceRouter,
  intelligentSchedulingRouter,
  monitorRouter,
  systemMgmtRouter,

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true, alwaysAdd: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
